<template>
  <div class="tech01">
    <button @click="search">抽奖</button>
    <button @click="readFileData">读取文件</button>
  </div>
</template>

<script setup>

let rand = (m, n) => {
  return Math.ceil(Math.random(n - m + 1) * n - 1);
}

let search = () => {
  const p = new Promise((resolve, reject) => {
    setTimeout(() => {
      let n = rand(1, 100);
      if (n < 30) {
        resolve(n)
      } else {
        reject(n)
      }
    }, 500);
  });

  p.then((value) => {
    alert("中奖 " + value);
  }, (reason) => {
    alert("再接再厉 " + reason);
  })
}

let readFileData = () => {
  new Promise((resolve, reject) => {
    import('./index.vue').then((err, data) => {
      if (err) reject(err)
      resolve(data)
    })
  }).then((value) => {
    console.log(value)
  }, (reason) => {
    console.log(reason)
  }).catch((e) => {
    console.error(e);
  });
}
</script>

<style scoped>
@media (min-width: 1024px) {
  .tech01 {
    min-height: 100vh;
    align-items: center;
  }
}
</style>
